package org.support.small.mallms.controller;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.support.small.infrastructure.utils.WebUtils;
import org.support.small.infrastructure.website.Languages;
import org.support.small.infrastructure.Tables;
import org.support.small.mallms.contants.URLContants;
import org.support.small.mallms.contants.WebSiteURLContants;
import org.support.small.mallms.query.LanguagesQuery;
import org.support.small.mallms.service.LanguagesService;

import javax.annotation.Resource;

@RestController
@RequestMapping(WebSiteURLContants.PREFIX_LANGUAGES)
public class LanguagesController {
    @Resource
    private LanguagesService languagesService;

    @PostMapping(URLContants.SEARCH)
    public Object search(Page<Languages> page, @RequestBody LanguagesQuery query) {
        QueryWrapper wrapper = WebUtils.createQuery(query, Tables.LANGUAGES.UPDATE_TIME.desc());
        languagesService.search(page, wrapper);
        return page;
    }
}
